package com.caoji.entity;

import com.caoji.dto.BaseDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description： User: caoji
 * Date: 2020/12/4
 * Time: 11:34
 */

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CategoryDto extends BaseDTO {
    private Long id;
    private String name;
    private Long parentId;
    private Boolean isParent;
    private Integer sort;

    public CategoryDto(BaseEntity entity) {
        super(entity);
    }

    /**
     * 将PO集合转为DTO集合
     * @param list PO对象的集合
     * @param <T> PO的类型
     * @return DTO集合
     */
    public static <T extends BaseEntity> List<CategoryDto> convertEntityList(Collection<T> list){
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(CategoryDto::new).collect(Collectors.toList());
    }
}